package com.myersinfosys.protrack.vfs;

import java.io.File;

import org.apache.commons.io.IOCase;
import org.apache.commons.io.filefilter.AbstractFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileType;

/** FileSessionSelector - Public class handling the filtering, globbing and traversing of a file session.
*
* @author E.Morris
* @version 4/15/2011
*/
public class FileSessionSelector implements FileSelector {

	private AbstractFileFilter globFilter;

	public FileSessionSelector(String globPattern) {
		globFilter = new WildcardFileFilter(globPattern, IOCase.SYSTEM);
	}

	@Override
	public boolean includeFile(FileSelectInfo file) throws Exception {
		File f = new File(file.getFile().getName().getPath());
		FileType ft = file.getFile().getType();
		return ((ft.equals(FileType.FILE) || ft.equals(FileType.FOLDER) ) && globFilter.accept(f));
	}

	@Override
	public boolean traverseDescendents(FileSelectInfo file) throws Exception {
		
		return (file.getFile().getType().hasChildren());
	}
}
